<template>
  <el-container class="allbody" onscroll="false">

    <el-main style="height: 100%; z-index: 5">
      <!--<Calendar-->
      <!--v-on:choseDay="clickDay"-->
      <!--v-on:changeMonth="changeDate"-->
      <!--&gt;</Calendar>-->
      <el-row style="width: 100%; height: 10%; margin-bottom: 20px">
        <el-form
          :inline="true"
          class="demo-form-inline"
          style="margin-top: 20px; margin-left: 10px"
        >
          <el-form-item>
            <el-input
              v-model="searchArgs.s001"
              placeholder="设备类别"
              style="width: 150px"
            ></el-input>
          </el-form-item>
          <el-form-item>
            <el-input
              v-model="searchArgs.s002"
              placeholder="设备品种"
              style="width: 150px"
            ></el-input>
          </el-form-item>

          <el-form-item>
            <el-input
              v-model="searchArgs.s003"
              placeholder="使用单位"
              style="width: 150px"
            ></el-input>
          </el-form-item>

          <el-form-item>
            <el-button style="color: #009bfe; width: 150px" @click="show"
              >查询</el-button
            >
          </el-form-item>

          <el-form-item>
            <el-button style="color: #fe3d15; width: 150px" @click="reset"
              >重置</el-button
            >
          </el-form-item>
          <!-- 
          <el-form-item>
            <el-link href="#" :underline="false" type="warning" target="_blank"
              >高级筛选</el-link
            >
          </el-form-item> -->
        </el-form>
      </el-row>

      <el-row style="width: 100%; height: 80%; margin-top: -2%">
        <el-table
          :data="tableData"
          style="
          width:80%
            height: 98%;
          "
          v-loading="loading"
          fit
          height="750"
        >
          <el-table-column prop="Id" label="序号" width="70"> </el-table-column>
          <el-table-column prop="f013" label="设备类别" width="120.5">
          </el-table-column>
          <el-table-column prop="f014" label="设备品种" width="160.5">
          </el-table-column>
          <el-table-column prop="f045" label="产品编号" width="150.5">
          </el-table-column>
          <el-table-column prop="f002" label="设备代码" width="180.5">
          </el-table-column>
          <el-table-column prop="f037" label="企业编号" widtFh="180.5">
          </el-table-column>

          <el-table-column prop="f015" label="规格型号" width="180.5">
          </el-table-column>

          <el-table-column prop="f032" label="使用单位" width="300.5">
          </el-table-column>

          <el-table-column prop="a006" label="监测数据" width="80.5">
            <template slot-scope="scope">
              <el-button
                type="text"
                style="text-decoration: underline;"
                @click="gotoDetail(scope.row.a006)"
                >{{ scope.row.a006 }}</el-button
              >
            </template>
          </el-table-column>
        </el-table>
        <el-pagination
          background
          @size-change="pageSizeChange"
          @current-change="pageChange"
          :current-page="currentPage"
          :page-sizes="[15, 30, 50, 80]"
          :page-size="pageSize"
          layout="total, sizes, prev, pager, next, jumper"
          :total="total"
        >
        </el-pagination>
      </el-row>
    </el-main>
  </el-container>
</template>

<script>
import ElContainer from "element-ui/packages/container/src/main";
import ElAside from "element-ui/packages/aside/src/main";
import ElHeader from "element-ui/packages/header/src/main";
import ElMain from "element-ui/packages/main/src/main";

import { get, get as userType, del, dels } from "@/api/sys/connSysAuthApi";
import { parseTime } from "@/utils";
import { req } from "@/api/base/BaseApi";
import Calendar from "vue-calendar-component";

export default {
  name: "index",
  components: { Calendar },
  comments: {
    ElMain,
    ElHeader,
    ElAside,
    ElContainer,
  },
  methods: {
    dateFormat(time) {
      var date = new Date(time);
      var year = date.getFullYear();
      /* 在日期格式中，月份是从0开始的，因此要加0
       * 使用三元表达式在小于10的前面加0，以达到格式统一  如 09:11:05
       * */
      var month =
        date.getMonth() + 1 < 10
          ? "0" + (date.getMonth() + 1)
          : date.getMonth() + 1;
      var day = date.getDate() < 10 ? "0" + date.getDate() : date.getDate();
      var hours =
        date.getHours() < 10 ? "0" + date.getHours() : date.getHours();
      var minutes =
        date.getMinutes() < 10 ? "0" + date.getMinutes() : date.getMinutes();
      var seconds =
        date.getSeconds() < 10 ? "0" + date.getSeconds() : date.getSeconds();
      // 拼接
      return (
        year +
        "-" +
        month +
        "-" +
        day +
        " " +
        hours +
        ":" +
        minutes +
        ":" +
        seconds
      );
    },
    tableRowStyle({ row, rowIndex }) {
      return "background-color: #02152f;color: #fff";
    },
    tableHeaderColor({ row, column, rowIndex, columnIndex }) {
      if (rowIndex === 0) {
        return "background-color: #2ec7c9;color: #fff;font-weight: 500;";
      }
    },
    handleSetLineChartData(type) {
      this.lineChartData = lineChartData[type];
    },
    getRowClass({ row, column, rowIndex, columnIndex }) {
      console.log("调用行样式");
      return {
        background: "#06134A",
        color: "#72C22D",
      };
    },
    getTableDataFormSon(data) {
      const tableDataTemp = data;
      this.tableData = [];
      for (let j = 9; j >= 0; j--) {
        const tableDataI = {};
        for (let i = 0; i < this.measurePoints.length; i++) {
          const point = this.measurePoints[i];
          const values = tableDataTemp.get(point);
          const date = new Date(values[j].name);
          if (i <= 0) {
            tableDataI["time"] =
              date.getFullYear() +
              "/" +
              (date.getMonth() + 1) +
              "/" +
              date.getDate() +
              " " +
              date.getHours() +
              ":" +
              date.getMinutes() +
              ":" +
              date.getSeconds();
          }
          tableDataI[point + "value"] = values[j].value;
        }
        this.tableData.push(tableDataI);
      }
      this.currTableData = [];
      for (let i = 0; i < this.measurePoints.length; i++) {
        const point = this.measurePoints[i];
        const values = tableDataTemp.get(point);
        const date = new Date(values[values.length - 1].name);
        this.currTableData.push({
          point: point,
          data: values[values.length - 1].value,
          time:
            date.getHours() + ":" + date.getMinutes() + ":" + date.getSeconds(),
        });
      }
    },
    addFixedData(list) {
      const dateHead = new Date();
      dateHead.setFullYear(2019);
      dateHead.setMonth(7);
      dateHead.setDate(26);
      const dateNow = new Date();
      const days = parseInt(
        (dateNow.getTime() - dateHead.getTime()) / (3600 * 1000 * 24)
      );
      list.unshift({
        no: 1,
        f013: "桥式起重机",
        f014: "冶金桥式起重机",
        f045: "0202001-2",
        f002: "41003405002006080017",
        f037: "一钢轧 008",
        f015: "QD200/63-23.5A7",
        f032: "马鞍山钢铁股份有限公司",
        a006: days + "天",
      });
    },
    async show() {
      // 只加一条数据
      const list = [];
      this.addFixedData(list);
      this.generateIds(list);
      this.tableData = list;
      this.total = 1;
    },
    reset() {
      this.searchArgs = {
        f002: "",
        f032: "",
        keyword: "",
      };
      this.show();
    },
    // 根据页面生成数据的ID
    generateIds(list) {
      for (const index in list) {
        list[index].Id = +index + 1 + this.pageSize * (this.currentPage - 1);
      }
    },
    gotoDetail(id) {
      this.$emit("switchDetail");
    },
    yearChange(id, type) {
      this.year = id;
    },
    monthChange(id, type) {
      this.month = id;
    },
    dayChange(id, type) {
      this.day = id;
    },
    change(event) {},
    // 页面大小改变
    async pageSizeChange(pageSize) {
      this.pageSize = pageSize;
      this.currentPage = 1;
      // 获取数据
      this.show();
    },
    // 页数改变
    async pageChange(page) {
      this.currentPage = page;
      // 获取数据
      this.show();
    },
  },
  created() {
    this.show();
  },
  data() {
    return {
      date: new Date(),
      year: "",
      month: "",
      day: "",
      mydate: "",
      calendar: {},
      searchArgs: {
        s001: "", // 设备类别
        s002: "", // 设备品种
        s003: "", // 使用单位名称
      },
      tableData: [], // 当前页面表格数据
      total: 0, // 表格数据总项数
      loading: false, // 表格是否在加载
      pageSize: 30, // 默认一页15项数据
      currentPage: 1,
      /*[{
          1: '1',
          2: 'MT-2001472',
          3: '浮顶型',
          4: '中化南通石化储运有限公司',
          5: '1份',
          6: ' ',
          7: ' ',
          8: ' ',
          9: ' ',
          10: ' '
        }, {
          1: '2',
          2: 'LYG-2001472',
          3: '浮顶型',
          4: '中化南通石化储运有限公司',
          5: '1份',
          6: ' ',
          7: ' ',
          8: ' ',
          9: ' ',
          10: ' '
        }]*/
    };
  },
  filters: {
    userTypeFilter(type) {
      let typeText = type;
      userTypes.forEach((val) => {
        if (type === val.value) {
          typeText = val.name;
        }
      });
      return typeText;
    },
    menuFilter(ids) {
      let length = 0;
      if (ids) {
        length = ids.length;
      }
      return length;
    },
    dateTimeFilter(time) {
      return parseTime(time);
    },
  },
  mounted() {
    let _this = this; //声明一个变量指向vue实例this,保证作用域一致
    (this.timer = setInterval(function () {
      _this.date = new Date(); //修改数据date
    }, 1000)),
      console.log(this.$route.path); // 输出当前页面的路由，如：/home
  },
};
</script>

<style lang="less" scoped>
.headerbackgroud {
}
.allbody {
  width: 100%;
  height: 1050px;
}
.rowclass {
  width: 100%;
  height: 50%;
}

#text {
  -webkit-text-fill-color: white;
}
.select {
  color: white;
}
.hello {
  // 未选中任何选项的时候 placeholder的样式 需要先选中父元素 增加权重
  /deep/ input::-webkit-input-placeholder {
    color: #fff;
  }
  /deep/ input::-moz-input-placeholder {
    color: #fff;
  }
  /deep/ input::-ms-input-placeholder {
    color: #fff;
  }

  //修改的是el-input的样式
  //一种方法是设置最里层el-input__inner的背景色 外层的两级父元素设置为透明色
  //另一种方法是从el-select到el-input__inenr的背景色都设置为需要的颜色
  /deep/ .el-select,
  /deep/ .el-input,
  /deep/ .el-input__inner {
    background-color: #08164d;
    color: #fff;
    border: 0px;
    border-radius: 0px;
    text-align: center;
  }
}
.map1,
.map2,
.map3 {
  position: absolute;
  opacity: 0.5;
}
.map1 {
  margin-left: 580px;
  margin-top: 230px;
  z-index: 2;
  animation: myfirst2 15s infinite linear;
}
.map2 {
  margin-left: 625px;
  margin-top: 275px;
  z-index: 3;
  opacity: 0.2;
  animation: myfirst 10s infinite linear;
}
.map3 {
  margin-left: 650px;
  margin-top: 300px;
  z-index: 1;
}
@keyframes myfirst2 {
  from {
    transform: rotate(0deg);
  }
  to {
    transform: rotate(359deg);
  }
}

@keyframes myfirst {
  from {
    transform: rotate(0deg);
  }
  to {
    transform: rotate(-359deg);
  }
}
</style>
